package be.ipl.pigolo.testUcc;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import org.junit.Before;
import org.junit.Test;

import be.ipl.pigolo.domaine.Partie;
import be.ipl.pigolo.usecases.GestionPartie;

public class TestQuitter {

	private static GestionPartie gp;
	private Partie partie;

	@Before
	public void setUp() throws Exception {
		try {
			Context jndi = new InitialContext();
			gp = (GestionPartie) jndi
					.lookup("ejb:PigoloEAR/PigoloEJB/GestionPartieImpl!be.ipl.pigolo.usecases.GestionPartie");
			assertNotNull(gp);
		} catch (NamingException e) {
			e.printStackTrace();
		}

	}

	@Test
	public void testQuitterPartieVide() {
		partie = new Partie("",5);
		assertFalse(this.partie.finDePartie());
	}

	@Test
	public void testQuitterPartieEtatNonEnCours() {
		partie = new Partie("partie29",5);
		assertFalse(this.partie.finDePartie());
	}

	@Test
	public void testQuitterPartieValide() {
		partie = new Partie("partie30",5);
		this.gp.creerPartie(partie.getNom(), 30);
		this.partie.commencerPartie();
		assertTrue(this.partie.finDePartie());
	}
}
